package com.ycz.controller;


import com.ycz.commons.CodeMsg;
import com.ycz.commons.Result;
import com.ycz.entity.User;
import com.ycz.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ycz
 * @since 2021-10-10
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @PostMapping("/login")
    public Result login(@RequestBody User user){
        System.out.println(user);

        Map<String,Object> map1=new HashMap<>();
        map1.put("username",user.getUsername());
        map1.put("password",user.getPassword());
        Collection<User> mUsers = userService.listByMap(map1);

        System.out.println(mUsers);

        if (mUsers.isEmpty()){
           return new Result(CodeMsg.USER_USER_PASSWORD_ERROR);
        }

        return new Result();
    }


    @GetMapping("/list")
    public List<User> getList(){
//        List<User> users= userService.list(null);
//        return new ResponseEntity.ok(users);
        return userService.list(null);
    }

}

